<!--
 * @Descripttion: 
 * @version: 
 * @Author: cyj
 * @Date: 2022-12-26 12:12:33
-->
<template>
    <div class="topsonglist">
        <div class="top-img">
            <img :src="playlist.coverImgUrl" alt="">
        </div>
        <div class="top-info">
            <div class="title">
                <span class="com">歌单</span>
                <span class="name">{{ playlist.name }}</span>
            </div>
            <div class="create">
                <div class="avat">
                    <img :src="playlist.creator?.avatarUrl" alt="">
                </div>
                <span class="nickname">{{ playlist.creator?.nickname }}</span>
                <div class="time">{{ time }}创建</div>
            </div>
            <!-- 相关操作 -->
            <div class="btn">
                <el-button type='danger' icon="VideoPlay" @click='playAll'>播放全部</el-button>
                <el-button class="e" :icon="isSub ? 'FolderChecked' : 'FolderAdd'" @click="subSongList">{{ isSub ? '已收藏'
                    : '收藏'
                }}({{
    instance.proxy.$formatNums.formatNum(playlist.subscribedCount)
}})</el-button>
                <el-button class="e" icon="Link">分享({{ instance.proxy.$formatNums.formatNum(playlist.shareCount)
                }})</el-button>
            </div>
            <!-- 相关标签 -->
            <div class="tags">
                <span>标签:</span>
                <span class="ss" v-for="(item, index) in playlist.tags" :key="index">{{ item }}</span>
            </div>
            <!-- 歌曲数量，歌单播放量 -->
            <div class="song-count">
                歌曲:<span> {{ playlist.trackCount }}</span>
                播放:<span> {{ instance.proxy.$formatNums.formatNum(playlist.playCount) }}</span>
            </div>
            <!-- 歌单描述 -->
            <div class="song-info">
                简介:<span>{{ playlist.description }}</span>
            </div>
        </div>
    </div>
</template>

<script setup>
//引入vueuse
import { useDateFormat } from '@vueuse/core'
import { getCurrentInstance, ref, computed } from 'vue'
import { useUserStore } from '@/store/user.js'

const instance = getCurrentInstance()
//创建仓库
const user = useUserStore()

defineProps({
    //歌单信息
    playlist: {
        type: Object,
        default: {}
    },
    //是否收藏
    isSub: {
        type: Boolean
    }
})
const emit = defineEmits(['subSongListBy', 'playAllSong'])

//格式化时间
const time = computed(() => {
    return (useDateFormat(instance.props.playlist?.createTime, 'YYYY-MM-DD')).value
})

//点击收藏歌单
function subSongList() {
    //先判断是否登录
    if (!user.isLogin) {
        instance.appContext.config.globalProperties.$message({
            type: 'warning',
            message: '登录后才能收藏',
            showClose: true
        })
        return;
    }
    //触发父组件的自定义事件
    emit('subSongListBy')
}

//点击播放全部
function playAll() {
    emit('playAllSong')  //触发自定义函数
}

</script>

<style lang="scss" scoped>
.topsonglist {
    height: 200px;
    margin: 30px;
    display: flex;

    .top-img {
        height: 200px;
        width: 200px;

        img {
            height: 100%;
            width: 100%;
        }
    }

    .top-info {
        margin-left: 20px;
        height: 200px;
        width: 1150px;

        .title {
            .com {
                color: #ec4141;
                padding: 0px 5px;
                border: 1px solid #ec4141;
                border-radius: 5px;
            }

            .name {
                margin-left: 10px;
                font-weight: 700;
                font-size: 20px;
            }
        }

        .create {
            display: flex;
            align-items: center;
            margin-top: 10px;

            .avat {
                margin-right: 10px;
                height: 30px;
                width: 30px;

                img {
                    height: 100%;
                    width: 100%;
                }
            }

            .nickname {
                cursor: pointer;
                font-size: 10px;
                color: #507daf;

                &:hover {
                    color: #0b58b0;
                }
            }

            .time {
                margin-left: 10px;
                font-size: 10px;
                color: #666666;
            }
        }

        .btn {
            margin-top: 10px;
        }

        .tags {
            margin-top: 10px;

            span {
                margin-right: 5px;
                cursor: pointer;
            }

            .ss {
                color: #507daf;

                &:hover {
                    color: #0b58b0;
                }
            }
        }

        .song-count {
            margin-top: 5px;

            span {
                margin-left: 5px;
                font-size: 10px;
                color: #666666;
            }
        }

        .song-info {
            margin-top: 5px;
            height: 40px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;

        }
    }
}

// 修改按钮样式
.e:focus,
.e:hover {
    color: black;
    background-color: #f2f2f2;
    border-color: #d9d9d9;
}
</style>